#include "m_gui/example/m_gui_init.h"
#include "m_gui/example/m_gui_comm.h"
#include "key_board/key_board.h"
#include "oled.h"
#include "debug.h"

static M_U32 key_up(void);
static M_U32 key_down(void);
static M_U32 key_left(void);
static M_U32 key_right(void);
static M_U32 key_enter(void);
static M_U32 key_exit(void);

MENU_GUI gui;

opsTypeDef ops = {
	.pset = (void (*)(M_U16, M_U16, M_U8))OLED_DrawPoint,
	.pclear = (void (*)(void))OLED_clcScreen,
	.pdrawBitMap = (void (*)(M_U16, M_U16, M_U16, M_U16, const M_U8 *))OLED_BitMapDisp,
	.pputString = (void (*)(M_U16, M_U16, M_U8, void *))OLED_INT_CharDisp,
	.pputString_x = (void (*)(M_U16, M_U16, M_U32, M_U8, void *))OLED_INT_CharDisp_x,
};

keyTypeDef key = {
	.up = key_up,
	.down = key_down,
	.left = key_left,
	.right = key_right,
	.enter = key_enter,
	.exit = key_exit,
};

void oled_gui_init(void)
{
	gui_init(&gui,&ops,&key,NULL);
	gui_select(&gui);
}

void oled_gui_start(struct sMenu *start)
{
//	gui_set_active(start);
	
	extern struct sMenu page[];
	gui_set_active(page);
	gui_give_sig(EVENT_ALL);
}

void oled_gui_key_scan(void)
{
	Key_Scan();
	gui_key_scan();
}

M_U32 key_up(void)
{
	return (KeyGetState(KEY_UP) == KEY_RELEASE);
}

M_U32 key_down(void)
{
	return (KeyGetState(KEY_DOWN) == KEY_RELEASE);
}

M_U32 key_left(void)
{
	return (KeyGetState(KEY_LEFT) == KEY_RELEASE);
}

M_U32 key_right(void)
{
	return (KeyGetState(KEY_RIGHT) == KEY_RELEASE);
}

M_U32 key_enter(void)
{
	return (KeyGetState(KEY_ENTER) == KEY_RELEASE);
}

M_U32 key_exit(void)
{
	return (KeyGetState(KEY_EXIT) == KEY_RELEASE);
}
